<?php
    class Connection
    {
        public static $statement;
        public static function getConnect()
        {
            mysql_connect(Config::$hostname, Config::$username, Config::$password) or header("Location: ?module=error&action=sql&error=" . mysql_error());
            mysql_select_db(Config::$dbname) or header("Location: ?module=error&action=sql&error=" . mysql_error());
        }
        public static function setQuery($statement)
        {
            Connection::$statement = mysql_query($statement) or header("Location: ?module=error&action=sql&error=" . urlencode(mysql_error()));
        }
        public static function setQueryf()
        {
			$count = func_num_args();
    		$arg_list = func_get_args();
            for ($i = 1; $i < $count; $i++) {
				if(!is_numeric($arg_list[$i]))
					$params[$i] = mysql_real_escape_string($arg_list[$i]);
				else
               		$params[$i] = $arg_list[$i];
            }
			$statement = vsprintf(func_get_args()[0], $params);
			Connection::setQuery($statement);
        }
        public static function getQuery()
        {
			return Connection::$statement;
        }
        public static function fetch()
        {
            $row = mysql_fetch_array(Connection::$statement);
            return $row;
        }
        public static function fetchAll($type=MYSQL_NUM)
        {
            $list = array();
            $num  = 0;
            while ($row = mysql_fetch_array(Connection::$statement, $type))
            {
                $list[$num++] = $row;
            } //$row = mysql_fetch_array(Connection::$statement)
            return $list;
        }
    }
?>